<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<%@ include file="/common/meta.jsp" %>
</head>

<body>

	<div class="place">
		<span>位置：</span>
		<ul class="placeul">
			<li><a href="${ctx}/ms">首页</a></li>
			<li><a href="#">实体分类</a></li>
		</ul>
	</div>
	<div class="rightinfo">
		<div class="formbody">
			<form id="searchForm">
				<ul class="seachform">

					<li><label>名称</label> <input type="text" name="name" value=""
						class="scinput" /></li>
					<li><div id="years"></div></li>
					<li><label>&nbsp;</label><input name="btnSrearch"
						type="submit" class="scbtn" value="查询" /></li>

				</ul>
			</form>
		</div>
		<div class="tools">
			<ul class="toolbar">
				<li><a href="${ctx}/ms/docCate/add"><span><img
							src="${ctx}/styles/images/t01.png" /></span>添加</a></li>

			</ul>
		</div>


		<div id="treegrid"></div>
	</div>

	<script type="text/javascript">
		BUI.use([ 'bui/grid','bui/data', 'bui/overlay', 'bui/form',
				'bui/extensions/treegrid'], function(
				Grid,Data, Overlay, Form, TreeGrid) {					
		
			 var treestore = new Data.TreeStore({
				 url : '/ms/docCate/docCateTree',
				 autoLoad : true, //自动加载数据
			 })	;				
				var tree = new TreeGrid({
			        render : '#treegrid',
			        width : '100%',
			        //nodes : store,	
			        store : treestore,
			        checkType: 'none',			       
			        columns : [
			          {title : '',dataIndex :'',width:'30%'}, 
			          {title : '标识',dataIndex :'field1',width:'20%'}, 
			          {title : '标识名称',dataIndex :'name',width:'30%'}, 			         
			          {
							title : '操作',
							dataIndex : 'd',
							width:'20%',
							renderer : function (value,obj) {
				            return '<span class="grid-command edit">编辑</span><span class="grid-command delete">删除</span>';
				          }}
			        ]			        
			      });
			 tree.render();	
			             					
			//创建表单，表单中的日历，不需要单独初始化
			var form = new BUI.Form.HForm({
				srcNode : '#searchForm'
			}).render();

			form.on('beforesubmit', function(ev) {
				//序列化成对象
				var obj = form.serializeToObject();
				//obj.start = 0; //返回第一页
				treestore.load(obj);
				return false;
			});
			/*
			grid.on('cellclick',function  (ev) {
		          var record = ev.record, //点击行的记录
		            field = ev.field, //点击对应列的dataIndex
		            target = $(ev.domTarget); //点击的元素
		          if(target.hasClass('edit')){
		           
		            window.location.href = "/ms/docCate/edit/" + record['id'];   
		          }
		 
		          if(target.hasClass('delete')){
		        	  BUI.Message.Confirm('确认删除么？', function () {
			            	
			                $.post("/ms/docCate/delete/"+record['id'],function (data, status) {			                	
			                	if (data.success) {			                		
			                        store.load();//删除成功重载grid表格数据
			                    } else {
			                        BUI.Message.Alert("删除错误", "error");
			                    }			                  
			                });  
			            }, 'question');	
		          }
		 
		        });
			*/
			//删除操作--这里是批量操作的写法
		       $('#btnDel').on('click', function () {
		    	 
		            var selections = grid.getSelection();//获取表格选择的数据行
		            if (!selections || selections.length <= 0) {
		                BUI.Message.Alert("请选择要删除数据项，可多选", "warning");
		                return;
		            }
		            BUI.Message.Confirm('确认删除么？', function () {
		                var ids = {};//批量删除的数组ID
		                for (var i = 0; i < selections.length; i++) {
		                    ids[i] = selections[i].id;
		                }                
		                
		                $.post("/ms/docCate/delDoc"+ids,function (data, status) {
		                	
		                	if (data.success) {
		                        store.load();//删除成功重载grid表格数据
		                    } else {
		                        BUI.Message.Alert("删除错误", "error");
		                    }	                  
		                });    				
		              
		            }, 'question');
		            return false;
		        });

		});
		//**检索	

	</script>
</body>

</html>
